package com.uff.hmstpa.util.date;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.DateTimeFormatterBuilder;

import com.uff.hmstpa.model.mediator.ModelMediator;

public class DateParse {

	public static Date parseStringDate(String time) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm");
		try {
			return df.parse(time);
		} catch (ParseException ex) {
			try {
				df = new SimpleDateFormat("dd-MM-aaaa hh:mm");
				return df.parse(time);
			} catch (ParseException ex2) {
				Logger.getLogger(ModelMediator.class.getName()).log(Level.SEVERE, null, ex);
				return null;
			}
		}
	}

	public static String parseDateToString(DateTime time) {
		DateTimeFormatter dtf = new DateTimeFormatterBuilder().appendYear(4, 4).appendLiteral("-").appendMonthOfYear(2).appendLiteral("-")
				.appendDayOfMonth(2).appendLiteral(" ").appendHourOfDay(2).appendLiteral(":").appendMinuteOfHour(2).toFormatter();

		return time.toString(dtf);
	}
}
